<%--
  Created by IntelliJ IDEA.
  User: hkw14
  Date: 2021/5/2
  Time: 20:13
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>添加用户</title>
    <link rel="stylesheet" href="${ctx}/resource/layui/css/layui.css">
    <style>
        .formInfo{
            position:absolute;
            top:50%;
            left:50%;
            transform:translate(-50%,-50%);
        }
    </style>
</head>
<body>
<div class="formInfo">
<form class="layui-form" style="padding:10px" >
    <div class="layui-form-item ">
        <label class="layui-form-label">
            用户姓名:
        </label>
        <div class="layui-input-inline">
            <input class="layui-input" id="realName">
        </div>
    </div>
    <div class="layui-form-item ">
        <label class="layui-form-label">
            用户账号:
        </label>
        <div class="layui-input-inline">
            <input class="layui-input" id="username">
        </div>
    </div>
    <div class="layui-form-item ">
        <label class="layui-form-label">
            用户密码:
        </label>
        <div class="layui-input-inline">
            <input class="layui-input" id="password">
        </div>
    </div>
    <div class="layui-form-item ">
        <label class="layui-form-label">
            用户角色:
        </label>
        <div class="layui-input-inline">
            <select id="role">
                <option value="2">业务员</option>
                <option value="1">管理员</option>
            </select>
        </div>
    </div>
    <div class="layui-row">
        <div class="layui-col-md6">
            <center>
            <button id="save" type="button" style="text-align: center;" class="layui-btn">提交</button>
            </center>
        </div>
        <div class="layui-col-md6">
            <center>
            <button type="reset" style="text-align: center;" class="layui-btn layui-btn-warm" >重置</button>
            </center>
        </div>
    </div>
</form>
</div>
<script src="${ctx}/resource/layui/layui.js"></script>
<script type="text/javascript">
    layui.use(['form','jquery','layer'], function () {
        var $ = layui.jquery,
            form = layui.form,
            layer = layui.layer;
        $("#save").click(function () {
            var userName = $("#username").val();
            var realName = $("#realName").val();
            var password = $("#password").val();
            var role = $("#role").val();
            console.log(userName+realName+password+role);
            $.post("user.do?type=add",{'userName':userName,'realName':realName,'password':password,'role':role},function(rs){
                if(rs.code != 200){
                    layer.msg(rs.msg);
                }else{
                    layer.msg("用户添加成功");
                }
            });
        })
    });
</script>
</body>
</html>
